package com.bobamrz.frontend;

import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

/**
 * @author Vladimir Morozov
 *
 */
public class RemoveFromClipboardAjaxServlet extends SecuredSuperServlet {

	private static final long serialVersionUID = -2984347123174468315L;
	private Logger log = Logger.getLogger(RemoveFromClipboardAjaxServlet.class);

	@Override
	protected void securedGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		log.debug("adding to clipboard");
		String idsParam = req.getParameter("ids");
		if(idsParam == null || idsParam.equals("")){
			throw new InvalidParameterException();
		} 
		String[] ids = idsParam.split(",");
		HttpSession session = req.getSession(false);
		List<Long> clipboardIds = (List<Long>) session.getAttribute("clipboard");
		for(String id : ids) {
			clipboardIds.remove(Long.parseLong(id));
		}
	}
}
